#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
    int i=10;
    pid_t id=fork();//创建子进程
    if(id<0)
    {
        perror("fork fail\n");
        return 1;
    }
    else if(id==0)
    {
        //child
        int cnt=0;
        while(1)
        {
            printf("I am child:  i:%3d &i:%p pid:%d\n",i,&i,getpid());
            sleep(1);
            if(cnt==3)//修改i的值
            {
                i=100;
            }
            cnt++;
        }
    }
    else
    {
        //father
        while(1)
        {
            printf("I am father: i:%3d &i:%p pid:%d\n",i,&i,getpid());
            sleep(1);
        }    
    }
    return 0;
}
